#pragma once

#include "..\\Classification.Base\cl_base_Data.h"

using namespace loirey;

class CSingleClassNaiveBayesModel
{
public:
	int Label;
	int FeatureDimension;
	double TotalTrainExampleWeightSum;
	double TotalTrainExampleFeatureValueSum;
	double P_c, logP_c;
	CSimpleTypeArray<double> vecF_FVS_f_given_c;
	CSimpleTypeArray<double> vecF_logP_f_given_c;

public:
	CSingleClassNaiveBayesModel();
	virtual void Clear();
	virtual void myInit(
		int Label, int FeatureDimension, double SmoothEpsilon);
	virtual double NewTrainExample(
		CLabeledDataSetForClassification* pSrcLDS,
		int ExampleIndex, double ExampleWeight);
	virtual void FinishTraining(
		double AllClassTotalTrainExampleWeightSum,
		bool fIgnorePriorDistribution);
	virtual double Classify(
		const CSparseVector& FeatureVector) const;
	virtual double Classify(
		CDataSetForClassification* pSrcLDS,
		int ExampleIndex) const;
};

class CMultiClassNaiveBayesModel
{
public:
	typedef map<int, int> CLabelMapping;
	typedef CSimpleTypeArray<CSingleClassNaiveBayesModel> CListSingleClassNBM;

public:
	int AmountClass;
	CLabelMapping lbl2mdl;
	CListSingleClassNBM ListNBM;
	int FeatureDimension;
	double TotalExampleWeightSum;

public:
	CMultiClassNaiveBayesModel();
	virtual void Clear();
	virtual void Train(
		CLabeledDataSetForClassification* pSrcLDS,
		const CWeightedClassificationExampleList& TrainingExampleList,
		bool fIgnorePriorDistribution);
	virtual void ToggleWhetherIgnorePriorDistribution(
		bool fIgnorePriorDistribution);
	virtual int Classify(
		CDataSetForClassification* pSrcLDS,	int ExampleIndex,
		int& DstLabel, double& DstConfidence) const;
	virtual int Classify(
		const CSparseVector& FeatureVector,
		int& DstLabel, double& DstConfidence) const;
};

